package com.camps.sdk.encrypt;

import com.camps.sdk.common.ExceptionCode;
import com.camps.sdk.entity.BatchWhiteCall;
import com.camps.sdk.entity.WhiteCall;
import com.camps.sdk.exception.BaseException;
import com.camps.sdk.utils.UnicodeUtil;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 10:11 2021/9/1
 * @Description
 */
public class BatchWhiteCallCommand implements BuildCommand {
    @Override
    public String splicingParameters(String imei, Object params) {
        if (!(params instanceof BatchWhiteCall)) {
            throw new BaseException(ExceptionCode.PARAMETER_ERROR);
        }
        BatchWhiteCall batchWhiteCall = (BatchWhiteCall) params;
        String commandNumber = batchWhiteCall.getCommandNumber();
        List<WhiteCall> whiteCallList = batchWhiteCall.getWhiteCallList();
        StringBuilder sb = new StringBuilder("*WT,");
        sb = sb.append(imei).append(",PBWLALL,").append(commandNumber);
        for (WhiteCall whiteCall : whiteCallList) {
            String name = whiteCall.getName();
            String phone = whiteCall.getPhone();
            Integer type = whiteCall.getType();
            Integer pictureId = whiteCall.getPictureId();
            Integer sequence = whiteCall.getSequence();
            if (sequence == null || sequence > 25) {
                throw new BaseException(ExceptionCode.WHITE_CALL_SEQUENCE_ERROR);
            }
            // 判断姓名是否为空，去决定是否进行编码
            if (name != null && !"".equals(name)) {
                name = UnicodeUtil.gbEncoding(name);
            }
            sb = sb.append(",").append(sequence).append(",").append(phone).append(",").append(type).append(",,")
                    .append(name).append(",").append(pictureId).append(",");
        }
        return sb.toString();

    }
    private class Invalid {
        private void invalid() {

        }
}



}